package tests;



import main.Conference;
import main.Manuscript;
import main.Review;
import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;

/**
 * JUnit tests for UpdateReview() in Conference
 * 
 * @author Daniel Anderson
 * @version 12/3
 */
public class UpdateReviewTest extends TestCase{
	
	Manuscript conf_manuscript1;
	Conference conf1;
	Review review1;
	Review review2;
	Review reviewodd;
	int indexofreplaced;
	
	/**
	 * Initializes objects used in tests.
	 */
	@Before
	public void setUp() {
		conf_manuscript1 = new Manuscript();
		conf1 = new Conference();
		review1 = new Review();
		review2 = new Review();
		reviewodd = new Review("odd", "Dan", "234", "Test");
		conf1.addManuscript(conf_manuscript1);
		conf1.addReview(conf_manuscript1, review1);
		conf1.addReview(conf_manuscript1, review2);
		indexofreplaced = conf_manuscript1.getReviews().indexOf(review2);
	}//end of setUp
	
	/**
	 * Tests the functionality of updateReview()
	 * 
	 * First two assertions borrowed from Cristopher
	 * for easy setup testing. 
	 * 12/1 -- Holly made corrections to setup() so tests pass (were failing)
	 */
	@Test
	public void testUpdate() {
		assertEquals("Initialized correctly?",
				conf_manuscript1.getReviews().size(), 2);
		assertEquals("Initialized correctly?", 
				conf1.getManuscripts().size(), 1);
		assertTrue("review1 is is inside the manuscript?", 
				conf_manuscript1.getReviews().contains(review1));
		assertTrue("review2 is is inside the manuscript?", 
				conf_manuscript1.getReviews().contains(review2));	
		
		//Now we updateReview
		conf1.updateReview(conf_manuscript1,
				review2, reviewodd);
		
		assertFalse("Was review1 replaced?", 
				!conf_manuscript1.getReviews().contains(review1));
		assertTrue("Was review2 replaced?", 
				!conf_manuscript1.getReviews().contains(review2));
		assertTrue("Was review2 replaced by review odd?",
				conf_manuscript1.getReviews().contains(reviewodd));
		assertEquals("Was the index properly replaced?",
				conf_manuscript1.getReviews().indexOf(reviewodd),
				indexofreplaced);
	}//end of testUpdate
}//end of UpdateReviewTest
